package cz.data.common.kafka;

import cz.data.common.kafka.manage.KafkaDbManage;
import cz.data.common.support.YamlPropertySourceFactory;
import cz.data.common.support.db.DbType;
import cz.data.common.support.db.manage.DbManageRegistry;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource(value = "classpath:kafka-setting.yml", factory = YamlPropertySourceFactory.class, encoding = "UTF-8")
@EnableConfigurationProperties({KafkaProperties.class})
@AutoConfigureAfter(KafkaAutoConfiguration.class)
public class DataKafkaConfiguration {


    @Bean
    public DefaultKafkaListenerErrorHandler defaultKafkaListenerErrorHandler() {
        return new DefaultKafkaListenerErrorHandler();
    }

    static {
        DbManageRegistry.registry(KafkaDbManage::new, DbType.KAFKA);
    }
}
